import plotly.express as px
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go
import warnings
warnings.filterwarnings('ignore')
total_df = pd.read_excel("RAW POLLS.xlsx")
total_df
total_df.columns
total_df.isnull().sum()
total_df.info()
total_df.nunique()
total_df.describe()
sns.set(rc={'axes.facecolor':'w', 'figure.facecolor':'gold'})
fig, axes = plt.subplots(4,figsize=(18,25))
sns.countplot(total_df["year"],ax = axes[0],palette="Set1")
sns.countplot(total_df["type_simple"],ax = axes[1],palette="Set1")
sns.countplot(total_df["partisan"],ax = axes[2],palette="Set1")
sns.countplot(total_df["type_detail"],ax = axes[3],palette="Set1")
plt.xticks(color = "black",rotation=90)
plt.show()
from plotly.subplots import make_subplots
labels1 = ['1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012',
'2013','2014','2015','2016','2017','2018']
values1 = [801,12,2525,39,1232,84,2519,57,1872,24,4787,135,2381,51,3140,141,1423,38,1768,67,7]
labels2 = ['House-G','Sen-G','Gov-G','Pres-P','Pres-G']
values2 = [3662,5442,3766,4395,5838]
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels1, values=values1, name="YEAR"),1, 1)
fig.add_trace(go.Pie(labels=labels2, values=values2, name="TYPE SIMPLE"),1, 2)
fig.update_traces(hole=.5, hoverinfo="label+percent+name",textposition='inside')
fig.update_layout({'plot_bgcolor': 'rgb(240,230,140)','paper_bgcolor': 'rgb(154,205,50)'},font=dict(color="white"),
title_text="YEAR and TYPE SIMPLE",legend_title="YEAR",
annotations=[dict(text='YEAR', x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text='TYPE SIMPLE', x=0.86, y=0.5, font_size=20, showarrow=False)])
fig.show()
from plotly.subplots import make_subplots
labels3 = ["D","None","R","I"]
values3 = [475,22223,402,3]
labels4 = ['House-G','Sen-G','Gov-G','Gov-O','Pres-D','Pres-R','Pres-G','Sen-O','Sen-GR','Gov-GR','House-GS','Pres-RC','Sen-GS',
'House-OS','Gov-GS','House-GR','House-O','House-GSR']
values4 = [3464,5130,3651,72,2211,2181,5838,43,64,37,107,2,205,4,6,65,1,10]
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels3, values=values3, name="TYPE SIMPLE"),1, 1)
fig.add_trace(go.Pie(labels=labels4, values=values4, name="TYPE SIMPLE"),1, 2)
fig.update_traces(hole=.5, hoverinfo="label+percent+name",textposition='inside')
fig.update_layout({'plot_bgcolor': 'rgb(240,230,140)','paper_bgcolor': 'rgb(128,0,128)'},font=dict(color="white")
,title_text="PARTISAN and TYPE DETAIL",legend_title="TYPE DETAIL",
annotations=[dict(text='PARTISAN', x=0.15, y=0.5, font_size=20, showarrow=False),
dict(text='TYPE DETAIL', x=0.87, y=0.5, font_size=20, showarrow=False)],)
fig.show()
fig = px.histogram(total_df["year"],color_discrete_sequence=["crimson"],title="YEAR count")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(119,136,153)'},height = 400,width = 980,
font=dict(color="white"))
fig.show()
fig = px.histogram(total_df["type_simple"],color_discrete_sequence=["orange"],title="TYPE SIMPLE count")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(0,0,0)'},height = 400,width = 980,
font=dict(color="white"))
fig.show()
fig = px.histogram(total_df["type_detail"],color_discrete_sequence=["green"],title="TYPE DETAIL count")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(255,69,0)'},height = 400,width = 980,
font=dict(color="white"))
fig.show()
fig = px.histogram(total_df["partisan"],color_discrete_sequence=["darkblue"],title="PARTISAN count")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(255,255,0)'},height = 400,width = 980,
font=dict(color="black"))
fig.show()
fig = px.pie(total_df, values='year', names='pollster',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.RdBu,
title='POLLSTER RACE YEAR')
fig.update_traces(textposition='inside',hole = .4)
fig.update_layout({'paper_bgcolor': 'rgba(222, 993, 1000, 200)'},uniformtext_minsize=10,legend_title="POLLSTER",
uniformtext_mode='hide',font=dict(color="Blue"))
fig.show()
fig = px.sunburst(total_df, path=['type_simple','year'],hover_data=['type_simple','year'],color='year',)
fig.update_layout({'paper_bgcolor': 'rgb(0,0,0)'},title="YEAR wise count of TYPE SIMPLE",
font=dict(color="white"),margin = dict(t=100, l=100, r=0, b=0))
fig.show()
fig = px.sunburst(total_df, path=['type_detail','year'],hover_data=['type_detail','year'],color='year',)
fig.update_layout({'paper_bgcolor': 'rgb(0,0,0)'},title="YEAR wise count of TYPE DETAIL",
font=dict(color="white"),margin = dict(t=100, l=100, r=0, b=0))
fig.show()
fig = px.sunburst(total_df, path=['type_simple', 'type_detail',"year"], values="year",
hover_data=['type_simple', 'type_detail'],color = "year")
fig.show()
fig = px.pie(total_df, values='margin_actual', names='pollster', title='POLLSTER vs MARGINAL_ACTUAL',
color_discrete_sequence=px.colors.sequential.RdBu,)
fig.update_traces(textposition='inside',hole = .4)
fig.update_layout({'plot_bgcolor': 'rgb(245,255,250)','paper_bgcolor': 'rgb(255,215,0)'},uniformtext_minsize=10,
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.histogram(total_df,x="pollster",y="margin_actual",color="pollster",title='POLLSTER vs MARGINAL_ACTUAL')
fig.update_traces(marker=dict(size=15,line=dict(width=1,color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.update_layout({'plot_bgcolor': 'rgb(245,255,250)','paper_bgcolor': 'rgb(128,128,0)'}
,font=dict(color="white"),xaxis=dict(showticklabels=False)
,width = 980,height = 500,showlegend = False)
fig.show()
fig = px.scatter(total_df,x="pollster",y="margin_actual",color="pollster",title='POLLSTER vs MARGINAL_ACTUAL')
fig.update_traces(marker=dict(size=15,line=dict(width=1,color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.update_layout({'plot_bgcolor': 'rgb(245,255,250)','paper_bgcolor': 'rgb(244,164,96)'}
,font=dict(color="black"),xaxis=dict(showticklabels=False)
,width = 980,height = 500,showlegend = False)
fig.show()
fig = px.scatter(total_df, x="cand1_name",y= "cand1_pct",size="cand1_pct",
color="cand1_name", color_continuous_scale=px.colors.sequential.Viridis,
title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(0,250,154)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.box(total_df, x="cand1_name",y= "cand1_pct",color="cand1_name",title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(139,69,19)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.density_contour(total_df, x="cand1_name",y= "cand1_pct",color="cand1_name",
title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_traces(line_width=1.5)
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(199,21,133)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.pie(total_df, values='cand1_pct', names='cand1_name',
hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.RdBu,
title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgba(222, 993, 1000, 200)'},uniformtext_minsize=10,legend_title="CANDIDATE NAMES",
uniformtext_mode='hide',font=dict(color="Blue"))
fig.show()
fig = px.sunburst(total_df, path=['cand1_name','year'], values='cand1_pct', color='cand1_name'
,title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_layout({'paper_bgcolor': 'rgb(255,255,0)'},
font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.scatter(total_df, x="cand2_name",y= "cand2_pct",size="cand2_pct",
color="cand2_name", color_continuous_scale=px.colors.sequential.Viridis,
title='CANDIDATE 2 & CANDIDATE 2 PERCENTAGE')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(0,0,0)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.density_contour(total_df, x="cand2_name",y= "cand2_pct",color="cand2_name",
title='CANDIDATE 2 & CANDIDATE 2 PERCENTAGE')
fig.update_traces(line_width=1.5)
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(189,183,107)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 550)
fig.show()
fig = px.box(total_df, x="cand2_name",y= "cand2_pct",color="cand2_name",
title='CANDIDATE 2 & CANDIDATE 2 PERCENTAGE')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(128,128,0)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.pie(total_df, values='cand2_pct', names='cand2_name',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Jet,
title='CANDIDATE 2 & CANDIDATE 2 PERCENTAGE')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(255,140,0)'},uniformtext_minsize=10,legend_title="CANDIDATE NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.sunburst(total_df, path=['cand2_name','year'], values='cand2_pct', color='cand2_name'
,title='CANDIDATE 2 & CANDIDATE 2 PERCENTAGE')
fig.update_layout({'paper_bgcolor': 'rgb(220,220,220)'},font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.scatter(total_df, x="cand1_name",y= "cand1_actual",size="cand1_actual",
color="cand1_name", color_continuous_scale=px.colors.sequential.Viridis,
title='CANDIDATE 1 & CANDIDATE 1 ACTUAL')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(0,250,154)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.box(total_df, x="cand1_name",y= "cand1_actual",color="cand1_name",
title='CANDIDATE 1 & CANDIDATE 1 ACTUAL')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(128,128,0)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.pie(total_df, values='cand1_actual', names='cand1_name',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Jet,
title='CANDIDATE 1 & CANDIDATE 1 ACTUAL')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(255,140,0)'},uniformtext_minsize=10,legend_title="CANDIDATE NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.sunburst(total_df, path=['cand1_name','year'], values='cand1_actual', color='cand1_name'
,title='CANDIDATE 1 & CANDIDATE 1 ACTUAL')
fig.update_layout({'paper_bgcolor': 'rgb(220,220,220)'},font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.scatter(total_df, x="cand2_name",y= "cand2_actual",size="cand2_actual",
color="cand2_name", color_continuous_scale=px.colors.sequential.Viridis,
title='CANDIDATE 2 & CANDIDATE 2 ACTUAL')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(0,250,154)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.box(total_df, x="cand2_name",y= "cand2_actual",color="cand2_name",
title='CANDIDATE 2 & CANDIDATE 2 ACTUAL')
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(128,128,0)'},showlegend=False,
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 980,height = 600)
fig.show()
fig = px.pie(total_df, values='cand2_actual', names='cand2_name',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Jet,
title='CANDIDATE 2 & CANDIDATE 2 ACTUAL')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(255,140,0)'},uniformtext_minsize=10,legend_title="CANDIDATE NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.sunburst(total_df, path=['cand2_name','year'], values='cand2_actual', color='cand2_name'
,title='CANDIDATE 2 & CANDIDATE 2 ACTUAL')
fig.update_layout({'paper_bgcolor': 'rgb(220,220,220)'},font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.scatter(total_df, x="cand1_actual", y="cand1_pct", animation_frame="year",animation_group="cand1_name",
size="cand1_actual", color="cand1_name", hover_name="pollster",
size_max=60,title="CANDIDATE 1 ACTUAL & CANDIDATE 1 PERCENTAAGE")
fig.update_layout({'plot_bgcolor': 'rgb(240,255,255)','paper_bgcolor': 'rgb(169,169,169)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"))
fig.show()
fig = px.scatter(total_df, x="cand1_pct",y="cand1_actual",
trendline="ols",size_max=10,size = "cand1_actual",
color="cand1_name",title="CANDIDATE 1 ACTUAL & CANDIDATE 1 PERCENTAAGE")
fig.update_layout({'plot_bgcolor': 'rgba(111, 882, 999, 100)','paper_bgcolor': 'rgba(222, 993, 1000, 200)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.density_contour(total_df, x="cand1_pct", y="cand1_actual",
title="CANDIDATE 1 ACTUAL & CANDIDATE 1 PERCENTAAGE",
marginal_x="histogram", marginal_y="histogram")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(255,20,147)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"),
xaxis={'categoryorder':'category ascending'},width = 950)
fig.show()
fig = px.density_heatmap(total_df, x="cand1_actual", y="cand1_pct", animation_frame="year",
marginal_x="box", marginal_y="histogram",hover_data=['year','cand1_name'],
title="CANDIDATE 1 ACTUAL & CANDIDATE 1 PERCENTAAGE")
fig.update_layout({'paper_bgcolor': 'rgb(0,255,255)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 1000)
fig.show()
fig = px.scatter(total_df, x="cand2_actual", y="cand2_pct", animation_frame="year",animation_group="cand2_name",
size="cand2_actual", color="cand2_name", hover_name="pollster",
size_max=60,title="CANDIDATE 2 ACTUAL & CANDIDATE 2 PERCENTAAGE")
fig.update_layout({'plot_bgcolor': 'rgb(255,218,185)','paper_bgcolor': 'rgb(255,239,213)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.scatter(total_df, x="cand2_pct",y="cand2_actual",
trendline="ols",size_max=10,size = "cand2_actual",
color="cand2_name",title="CANDIDATE 2 ACTUAL & CANDIDATE 2 PERCENTAAGE")
fig.update_layout({'plot_bgcolor': 'rgb(253,245,230)','paper_bgcolor': 'rgb(188,143,143)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="white"))
fig.show()
fig = px.density_contour(total_df, x="cand2_pct", y="cand2_actual",
title="CANDIDATE 2 ACTUAL & CANDIDATE 2 PERCENTAAGE",
marginal_x="histogram", marginal_y="histogram")
fig.update_layout({'plot_bgcolor': 'rgb(255,255,255)','paper_bgcolor': 'rgb(255,192,203)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 950)
fig.show()
fig = px.density_heatmap(total_df, x="cand2_actual", y="cand2_pct", animation_frame="year",
marginal_x="box", marginal_y="histogram",hover_data=['year','cand2_name'],
title="CANDIDATE 2 ACTUAL & CANDIDATE 2 PERCENTAAGE")
fig.update_layout({'paper_bgcolor': 'rgb(255,250,205)'},
uniformtext_minsize=8, uniformtext_mode='hide',font=dict(color="black"),
xaxis={'categoryorder':'category ascending'},width = 1000)
fig.show()
fig = px.scatter_3d(total_df, x='cand1_pct', y='cand2_pct', z='cand3_pct',color = "cand1_name",
symbol='cand1_name', opacity=0.7,title="CANDIDATE 1,2,3 PAERCENTAGES")
fig.update_traces(marker=dict(size=8,
line=dict(width=1,
color='DarkGrey')),
selector=dict(mode='markers'))
fig.update_layout(showlegend = True)
fig.show()
fig = px.scatter_3d(total_df, x='cand1_pct', y='cand2_pct', z='cand3_pct',color = "cand2_name",
symbol='cand2_name', opacity=0.5,title="CANDIDATE 1,2,3 PAERCENTAGES")
fig.update_traces(marker=dict(size=8,
line=dict(width=1,
color='DarkGrey')),
selector=dict(mode='markers'))
fig.update_layout(showlegend = True)
fig.show()
# total_df["cand1_pct"].sum()
# total_df["cand2_pct"].sum()
# total_df["cand3_pct"].sum()
# total_df["cand1_actual"].sum()
# total_df["cand2_actual"].sum()
sns.set(rc={'axes.facecolor':'orange', 'figure.facecolor':'mistyrose'})
group_names=['cand1_pct','cand2_pct', 'cand3_pct']
group_size=[1031330.23,985459.39,61832.43]
subgroup_names=['cand1_actual','cand2_actual']
subgroup_size=[1119605.35410609,1056366.31309833]
a,b,c=[plt.cm.Blues, plt.cm.Reds, plt.cm.Greens]
fig, ax = plt.subplots(figsize=(18, 8))
ax.axis('equal')
mypie, _ = ax.pie(group_size, radius=1.3,labels=group_names,colors=[a(0.6), b(0.6), c(0.6)],
textprops={ 'color': 'deeppink','fontweight' :'bold','fontsize' : 15})
plt.setp( mypie, width=0.28, edgecolor='white')
mypie2, _ = ax.pie(subgroup_size, radius=1.3-0.3, labels=subgroup_names, labeldistance=0.50,
colors=[a(0.6), b(0.6), c(0.6)],
textprops={ 'color': 'black','fontweight' :'bold','fontsize' : 15})
plt.setp( mypie2, width=0.6, edgecolor='white')
plt.title("CANDIDATE 1,2,3 PAERCENTAGES,ACTUAL" ,fontdict = {'fontsize' : 20 ,'fontweight' :'bold' } , color = "green",loc ='left')
plt.show()
from plotly import graph_objects as go
fig = go.Figure(layout={'plot_bgcolor':'skyblue','title':'CANDIDATE 1,2,3 PAERCENTAGES,ACTUALS & MARGIN ACTUAL'})
fig.add_trace(go.Funnel(
name = "Candidate Percentages",
orientation = "h",
y = ["Cand1_pct","Cand2_pct","Cand3_pct"],
x = [1031330.23,985459.39,61832.43],marker={'color':['#FF1493','#FF69B4','#FFB6C1']},
textposition = "inside",
textinfo = "percent initial"))
fig.add_trace(go.Funnel(
name = "Candidate Actual Percentages",
orientation = "h",
y = ['cand1_actual','cand2_actual'],
x = [1119605.35410609,1056366.31309833],marker={'color':['#00FFFF','#E0FFFF']},
textposition = "inside",
textinfo = 'percent initial'))
fig.add_trace(go.Funnel(
name = "Margin Actual",
orientation = "h",
y = ["margin_actual"],
x = [63237.96101],marker={'color':['#FFD700']},
textposition = "inside",
textinfo = 'percent initial'))
fig.update_layout(height=650,width=1000,font=dict(color="black",size = 15))
fig.show()
fig = px.pie(total_df, values='bias', names='pollster',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Jet,
title='POLLSTER & BIAS')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(255,239,213)'},uniformtext_minsize=10,legend_title="POLLSTER NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.pie(total_df, values='rightcall', names='pollster',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Rainbow,
title='POLLSTER & RIGHTCALL')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(224,255,255)'},uniformtext_minsize=10,legend_title="POLLSTER NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.scatter(total_df, x="pollster",y= "rightcall",size="rightcall",color ="pollster",
hover_data=["year"],title='POLLSTER & RIGHT CALL')
fig.update_traces(marker=dict(size=20,line=dict(width=1,color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.update_layout({'plot_bgcolor': 'rgb(245,255,250)','paper_bgcolor': 'rgb(255,215,0)'}
,font=dict(color="black"),xaxis=dict(showticklabels=False)
,width = 980,height = 550,showlegend = False)
fig.show()
fig = px.sunburst(total_df, path=['rightcall','pollster'], values='rightcall', color='pollster'
,title='CANDIDATE 1 & CANDIDATE 1 PERCENTAGE')
fig.update_layout({'paper_bgcolor': 'rgb(240,255,255)'},
font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.pie(total_df, values='error', names='pollster',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Blackbody,
title='POLLSTER & ERROR')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(127,255,212)'},uniformtext_minsize=10,legend_title="POLLSTER NAMES",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.scatter(total_df, x="pollster",y= "error",size="error",color ="pollster",
hover_data=["year"],title='POLLSTER & ERROR')
fig.update_traces(marker=dict(size=20,line=dict(width=1,color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.update_layout({'plot_bgcolor': 'rgb(245,255,250)','paper_bgcolor': 'rgb(255,215,0)'}
,font=dict(color="black"),xaxis=dict(showticklabels=False)
,width = 980,height = 550,showlegend = False)
fig.show()
fig = px.pie(total_df.query("partisan != None"), values='rightcall', names='partisan',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.Blackbody,
title='PARISAN & RIGHT CALL')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(127,255,212)'},uniformtext_minsize=10,legend_title="PARISAN",
uniformtext_mode='hide',font=dict(color="black"))
fig.show()
fig = px.sunburst(total_df, path=['rightcall','partisan'], values='rightcall', color='partisan'
,title='PARISAN & RIGHT CALL')
fig.update_layout({'paper_bgcolor': 'rgb(240,255,255)'},
font=dict(color="black"),margin = dict(t=50, l=100, r=0, b=0))
fig.show()
fig = px.pie(total_df, values='pollno', names='comment',hover_data=["race","year","location"],
color_discrete_sequence=px.colors.sequential.YlOrRd,
title='POLL NUMBER & COMMENT')
fig.update_traces(textposition='inside',hole = .2)
fig.update_layout({'paper_bgcolor': 'rgb(0,0,0)'},uniformtext_minsize=10,legend_title="PARISAN",
uniformtext_mode='hide',font=dict(color="white"),showlegend = False)
fig.show()
fig = px.pie(total_df, values="samplesize", names="pollster",
title='SAMPLE SIZE vs POLLSTER',hole=.2,)
fig.update_traces(textposition='inside', textfont_color="black")
fig.update_layout({'paper_bgcolor': 'rgb(238,232,170)'},uniformtext_minsize=10, uniformtext_mode='hide',font=dict(color="black"))
fig.show()